package com.nuoniu.sibanyun.mapper.po;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.po.VPoPurchaseOrderMain;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 采购订单主表 Mapper 接口
 * </p>
 *
 * @author baiqiang
 * @since 2020-11-16
 */
@Mapper
@Component
public interface VPoPurchaseOrderMainMapper extends BaseMapper<VPoPurchaseOrderMain> {

    /**
     * 获取当天最新code
     * @author 小啊刚
     * @date 2020-11-21
     */
    @Select("select voucher_code from scp_order where date_format(create_date, #{dateStr})=date_format(now(), #{dateStr}) and company_id=#{companyId} order by id desc limit 1")
    String getNewestCode(Integer companyId, String dateStr);

    /**
     * 获取最新单据编码
     * @author 小啊刚
     * @date 2020-11-25
     */
    @Select("select * from scp_order where source_voucher_code=#{sourceVoucherCode} and company_id=#{companyId}")
    List<VPoPurchaseOrderMain> getBySourceCode(String sourceVoucherCode, Integer companyId);

    @Select("select * from scp_order where purchase_type_id = #{id}")
    List<VPoPurchaseOrderMain> getByPurchaseTypeId(Long id);
}
